#pragma once
#include <iostream>
#include <vector>
#include <ctemplate/template.h>

#include "oj_model.hpp"

class OjView
{
    public:
    static void DrawAllQuestions(std::vector<Question>& questions,std::string* html)
    {
        //1.创建template字典
        ctemplate::TemplateDictionary dict("all_questions");

        //2.遍历vector，vector中的每一个question都要创建成一个子字典
        for(const auto& ques:questions)
        {
            //根据vector中的各个题目创建子字典
            ctemplate::TemplateDictionary* child_dict=dict.AddSectionDictionary("question");
            child_dict->SetValue("id",ques.id_);
            child_dict->SetValue("id",ques.id_);
            child_dict->SetValue("title",ques.title_);
            child_dict->SetValue("star",ques.star_);
        }
        //3.对html页面进行填充
        
        //从磁盘中读取html文件。
        ctemplate::Template* tl=ctemplate::Template::GetTemplate("./template/all_questions.html",ctemplate::DO_NOT_STRIP);

        //渲染
        tl->Expand(html,&dict);
    }

    static void DrawOneQuestion(Question& ques,std::string* html)
    {
        ctemplate::TemplateDictionary dict("question");
        dict.SetValue("id",ques.id_);
        dict.SetValue("title",ques.title_);
        dict.SetValue("star",ques.star_);
        dict.SetValue("desc",ques.desc_);
        dict.SetValue("id",ques.id_);
        dict.SetValue("code",ques.header_cpp_);
        ctemplate::Template* tl=ctemplate::Template::GetTemplate("./template/question.html",ctemplate::DO_NOT_STRIP);
        tl->Expand(html,&dict);
    }


    static void DrawCaseResult(const std::string& error_no,const std::string& com_ret,const std::string& case_ret,std::string* html)
    {
        ctemplate::TemplateDictionary dict("question");
        dict.SetValue("errorNo",error_no);
        dict.SetValue("compile_result",com_ret);
        dict.SetValue("case_result",case_ret);
        ctemplate::Template* tl=ctemplate::Template::GetTemplate("./template/case_result.html",ctemplate::DO_NOT_STRIP);
        tl->Expand(html,&dict);
    }
};
